export const IMGURL = "	https://iotapi.sziton.com/afile/KGE2O3CEC8/"
export const APIURL = "https://iotapi.sziton.com/api/appapi/"
export const APPID = "0724ee6c163e06f54011ecbbac009aaa"
export const APPSECRET = "XenwE4VpZxRX0xMfSiqL3fAXj4QXv0pvMzfBzg5gCkdKgzzPq0JGUSFCEzS91vKy"
export const windowHeight = window.innerHeight || document.documentElement.clientHeight;
// 处理单位
const forunit=(weight,weight_unit)=>{
	let tjxdata = {
		weight:0,weight_unit:0
	}
  let tweight = 0
	switch(parseInt(weight_unit)){
    case 0://kg
      tjxdata.weight = parseFloat(weight).toFixed(2)
      tjxdata.weight_unit = parseInt(weight_unit)
      break
    case 2://LB
      tweight = parseFloat(weight).toFixed(1)*2.20460
      tweight = weight <= 0 ? 0 : formatDecimal(tweight,1)
      tjxdata.weight = tweight
      tjxdata.weight_unit = parseInt(weight_unit)
      break
    case 1://斤
      tweight = parseFloat(weight).toFixed(2)
      tweight = weight <= 0 ? 0 : formatDecimal(tweight,1)
      tjxdata.weight = tweight
      tjxdata.weight_unit = parseInt(weight_unit)
      break
    default:
        tjxdata.weight = parseFloat(weight).toFixed(2)
        tjxdata.weight_unit = 0
        break
  }
  console.error("forunit",tjxdata,weight,weight_unit)
  return tjxdata
}
// 单位为LB时对小数点的处理
function formatDecimal(num, decimal) {
  num = num.toString()
  let index = num.indexOf('.')
  if (index !== -1) {
    num = num.substring(0, decimal + index + 1)
  } else {
    num = num.substring(0)
  }
  return parseFloat(num).toFixed(decimal)
}

// 根据生日算年龄
const matAge=(bir,c_time)=>{
	var age = Math.ceil((c_time-bir)/31536000000);
	return age
}
// 过滤非正常数据
const fillter = (jxstate) =>{
  // 过滤非正常阻抗
  let tempbody_r_enc = 0
  tempbody_r_enc = jxstate.body_r_enc== null || jxstate.body_r_enc < 1 ? 0 : parseInt(jxstate.body_r_enc)
  parseFloat(jxstate.weight).toFixed(2) //不用截取
  jxstate.weight = jxstate.weight!= null || jxstate.weight!= undefined  ? jxstate.weight : 0
  // 首页获取显示
  let tempweight = 0
  tempweight =  jxstate.weight!= null || jxstate.weight!= undefined ? parseFloat(jxstate.weight).toFixed(2) : 0
  if(parseInt(jxstate.weight_unit) == 1){
    tempweight =  jxstate.weight!= null || jxstate.weight!= undefined  ? (jxstate.weight / 2.20460 ).toFixed(2) : 0
  }else{
    tempweight =  jxstate.weight!= null || jxstate.weight!= undefined ? jxstate.weight : 0
  }
  // 计算后的蓝牙数据
  const  weightdata = forunit(tempweight,jxstate.weight_unit)
  return weightdata
}

export {forunit,matAge}

// 体脂数据
// 1.体重                  9.内脏脂肪量
// 2.BMI                   10.骨率
// 3.脂肪率                11.骨量
// 4.脂肪量                12.基础代谢
// 5.肌肉率                 13.蛋白质
// 6.肌肉量                 14.身体年龄
// 7.水分                   15.去脂体重
// 8.内脏脂肪               16.肥胖等级 

// 身体类型bodyType 1. 隐胖型，2. 偏胖型，3. 肌肉型偏胖，4. 缺乏锻炼型，5. 标准型 ，6. 标准肌肉型，7. 偏瘦型，8. 偏瘦肌肉型，9. 肌肉发达型
// 健康等级healthLevel 1. 偏瘦，2. 标准，3. 超重，4. 重度肥胖
// obesityLevel肥胖等级 0. 不胖，1. 肥胖 1 级，2. 肥胖 2 级，3. 肥胖 3 级

// BMI: "20.420401464462"
// BMI_u: null
// BMR: "0"
// BMR_u: null
// bodyAge: "0"
// bodyAge_u: null
// bodyScore: "0"
// bodyScore_u: null
// bodyType: "0"
// bodyType_u: null
// boneKg: "0"
// boneKg_u: null
// boneRate: "0"
// boneRate_u: null
// controlFatKg: "0"
// controlFatKg_u: null
// controlMuscleKg: "0"
// controlMuscleKg_u: null
// controlWeight: "0"
// controlWeight_u: null
// device_id: 766
// downFat: "0"
// downFat_u: null
// downMuscle: "0"
// downMuscle_u: null
// fatKg: "0"
// fatKg_u: null
// fatRate: "0"
// fatRate_u: null
// healthLevel: "0"
// healthLevel_u: null
// id: 1327
// impedanceStatus: "-1"
// impedanceStatus_u: null
// muscleKg: "0"
// muscleKg_u: null
// muscleRate: "45.933413117451"
// muscleRate_u: null
// notFatWeight: "0"
// notFatWeight_u: null
// obesityLevel: "0"
// obesityLevel_u: null
// option_time: 1649659034671
// option_type: 1
// proteinPercentageKg: "0"
// proteinPercentageKg_u: null
// proteinPercentageRate: "0"
// proteinPercentageRate_u: null
// standardWeight: "0"
// standardWeight_u: null
// subcutaneousFatKg: "0"
// subcutaneousFatKg_u: null
// subcutaneousFatRate: "0"
// subcutaneousFatRate_u: null
// third_user_id: 231
// upFat: "0"
// upFat_u: null
// upMuscle: "0"
// upMuscle_u: null
// user_id: 4
// visceralFat: "0"
// visceralFatKg: "0"
// visceralFatKg_u: null
// visceralFat_u: null
// waterKg: "0"
// waterKg_u: null
// waterRate: "0"
// waterRate_u: null
// weight: "64.7"
// weight_u: null

const data1 = {
"weight": 64.7, //体重 [0: 61.739998,1: 75.46]
"BMI": 23.764921946740127, //BMI [0: 10,1: 21,2: 26] [0, 18.5, 24, 30]
"fatRate": 18.923810835629013,//脂肪率  [10, 21, 26]
"fatKg": 12.243705610651972,//脂肪量 [7.37, 15.47, 19.15]
"subcutaneousFatRate": 18.66742389136135,//皮下脂肪率  [8.6, 16.7, 20.7]
"subcutaneousFatKg": 12.077823257710794,//皮下脂肪量 []
"muscleRate": 42.865594318893855,//肌肉率 []
"muscleKg": 27.734039524324327,//肌肉量  [49.4, 59.4]
"waterRate": 57.81582689335393,//水分  [55, 65]
"waterKg": 37.406839999999995,//含水量 []
"visceralFat": 6,//内脏脂肪  [10, 14]
"visceralFatKg": 59.5882662993572,//内脏脂肪量 []
"boneRate": 4.046031590991707,//骨率 []
"boneKg": 2.617782439371635,//骨量  [2.8, 3]
"BMR": 1478.3615809729731,//基础代谢 [1642.4]
"proteinPercentageRate": 17.88826965394334,//蛋白质比例 []
"proteinPercentageKg": 11.57371046610134,//蛋白质含量 [16, 20]
"bodyAge": 30,//身体体年龄
"bodyScore": 90,//身体得分
"standardWeight": 59.895,//标准体重
"notFatWeight": 52.45629438934803,//去脂体重
"controlWeight": -4.805,//控制体重
"controlFatKg": -3.0844614290016095,//脂肪控制量
"controlMuscleKg": -1.7205385709983902,//肌肉控制量
"obesityLevel": 0,//肥胖等级 [18.5, 24.9, 29.9, 35, 40]
"healthLevel": 2,//健康等级
"bodyType": 3,//身体类型
"upFat": 0,//上臂脂肪(8极秤才有)
"downFat": 0,//下臂脂肪(8极秤才有)
"upMuscle": 0,//上臂肌肉(8极秤才有)
"downMuscle": 0,//下臂肌肉(8极秤才有)
"impedanceStatus": -1//阻抗状态
}
